package com.example.activityservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.activityservice.entity.Activity;
import com.example.activityservice.mapper.ActivityMapper;
import com.example.activityservice.service.ActivityService;
import org.springframework.stereotype.Service;

@Service // 标记为 Spring Bean
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {

    @Override
    public boolean publishActivity(Long activityId) {
        Activity activity = getById(activityId);
        if (activity == null) {
            return false;
        }
        activity.setStatus(2); // 状态2：已发布
        return updateById(activity);
    }

    @Override
    public Double calculateDuration(Activity activity) {
        long durationMillis = activity.getEndTime().toEpochSecond(null) - activity.getStartTime().toEpochSecond(null);
        return Math.round((durationMillis / 3600.0) * 10) / 10.0; // 转换为小时并保留1位小数
    }
}
